package com.example.design.factory.version6.homework;

public class ArrayBookBiz implements IBookBiz{

    private  static final   int CAPACITY=5;
    private   int count;  //代表有效图书数量
    private  Book[] books=new Book[CAPACITY];
    @Override
    public void add(Book b) {
        if(count==CAPACITY){
            System.out.println("数组已经满了。。。。。");
        }
        books[count++]=b;
    }

    @Override
    public void deleteByName(String name) {
            for(int i=0;i<count;i++){
                if(books[i].getBookName().equals(name)){
                        books[i]=null;
                        for(int k=i;k<count-1;k++){
                            books[k]=books[k+1];
                        }
                        books[count-1]=null;
                        count--;
                   return;
                }
            }
        System.out.println("要删除的书不存在。。。");
    }

    @Override
    public void outputAllBooks() {
        if(count==0){
            System.out.println("书本信息为空。。。。。");
        }
        for (int i=0;i<count;i++){
            if(books[i]!=null) {
                System.out.println(books[i]);
            }
        }
    }
}
